//
//  RightTopButton.m
//  StationManager
//
//  Created by 泽华伟业 on 17/3/10.
//  Copyright © 2017年 Helong. All rights reserved.
//

#import "RightTopButton.h"

@implementation RightTopButton

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.layer.borderColor = [UIColor blackColor].CGColor;
        self.layer.borderWidth = 1;
    }
    return self;
}

//故障label
- (UILabel *)faultLabel{
    if (!_faultLabel) {
        _faultLabel = [[UILabel alloc]init];
        [self addAndSetLableTypeWithLable:_faultLabel];
        [_faultLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self);
            make.left.equalTo(@5);
            make.right.equalTo(self);
            make.height.equalTo(self).dividedBy(3);
        }];
    }
    return _faultLabel;
}

- (UILabel *)normalLabel{
    if (!_normalLabel) {
        _normalLabel = [[UILabel alloc]init];
        [self addAndSetLableTypeWithLable:_normalLabel];
        [_normalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_faultLabel.mas_bottom);
            make.size.left.equalTo(_faultLabel);
        }];
    }
    return _normalLabel;
}

- (UILabel *)maintainLabel{
    if (!_maintainLabel) {
        _maintainLabel = [[UILabel alloc]init];
        [self addAndSetLableTypeWithLable:_maintainLabel];
        [_maintainLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@5);
            make.right.equalTo(self);
            make.top.equalTo(_faultLabel.mas_bottom);
            make.height.equalTo(_faultLabel);
        }];
    }
    return _maintainLabel;
}

- (UILabel *)urgentlyLabel{
    if (!_urgentlyLabel) {
        _urgentlyLabel  =[[UILabel alloc]init];
        [self addAndSetLableTypeWithLable:_urgentlyLabel];
        [_urgentlyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@5);
            make.right.equalTo(self);
            make.top.equalTo(_maintainLabel.mas_bottom);
            make.height.equalTo(_maintainLabel);
        }];
    }
    return _urgentlyLabel;
}

- (void)addAndSetLableTypeWithLable:(UILabel *)label{
    [self addSubview:label];
    [label setFont:[UIFont systemFontOfSize:11]];
    [label setTextAlignment:NSTextAlignmentLeft];

}

//设置一个lable上有不同的颜色
- (void)setAttributedStringWithFaultString:(NSString *)faultString NormalString:(NSString *)normalString MaintainString:(NSString *)maintainString UrgntlyString:(NSString *)urgntlyString {
    [self.faultLabel setAttributedText:[self getAttriubtedStringByString:faultString]];
//    [self.normalLabel setAttributedText:[self getAttriubtedStringByString:normalString]];
    [self.maintainLabel setAttributedText:[self getAttriubtedStringByString:maintainString]];
    [self.urgentlyLabel setAttributedText:[self getAttriubtedStringByString:urgntlyString]];
}
//转换字符串
- (NSMutableAttributedString *)getAttriubtedStringByString:(NSString *)string{
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc]initWithString:string];
    [attStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(6, string.length - 6)];
    return attStr;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
